﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SHW_UP.BP;

namespace SHW_UP.UI
{
    public partial class frmTimeZone : Form
    {
        public frmTimeZone()
        {
            InitializeComponent();
        }

        private void bindTimeZone()
        {
            DataTable dtTimeZone = new DataTable();
            dtTimeZone.Columns.Add("Value");
            dtTimeZone.Columns.Add("Name");
            DataRow drSex;
            drSex = dtTimeZone.NewRow();
            drSex[0] = "1";
            drSex[1] = "东区";
            dtTimeZone.Rows.Add(drSex);
            drSex = dtTimeZone.NewRow();
            drSex[0] = "0";
            drSex[1] = "西区";
            dtTimeZone.Rows.Add(drSex);
            this.timezoneCombox.ValueMember = "Value";
            this.timezoneCombox.DisplayMember = "Name";
            this.timezoneCombox.DataSource = dtTimeZone;
            this.timezoneCombox.DropDownStyle = ComboBoxStyle.DropDownList;
        }

        private DataTable dt = new DataTable();
        private void frmTimeZone_Load(object sender, EventArgs e)
        {
            bindTimeZone();
            this.timezoneGridView.Columns.Clear();
            this.timezoneGridView.ReadOnly = true;
            dt.Columns.Add("时区");
            dt.Columns.Add("GMT");
            DataRow dr1 = dt.NewRow();
            try
            {
                if (InfoUtils.parTable["timezone"].Equals("+"))
                {
                    dr1[0] = "东区";
                }
                else
                {
                    dr1[0] = "西区";
                }
            }
            catch (Exception es)
            {
                Console.WriteLine(es.Message);
            }
            dr1[1] = InfoUtils.parTable["gmt"];
            dt.Rows.Add(dr1);
            this.timezoneGridView.DataSource = dt;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void GridView_RowClick(object sender, EventArgs e)
        {
            if (this.timezoneGridView.SelectedRows.Count > 0)
            {
                this.timezoneCombox.SelectedText = this.timezoneGridView.Rows[0].Cells[0].Value.ToString();
                this.gmtTextView.Text = this.timezoneGridView.Rows[0].Cells[1].Value.ToString();
            }
        }
        private void timezoneModify_Click(object sender, EventArgs e)
        {
            string passwd = string.Empty;
            if (InfoUtils.parTable.Contains("passwd"))
            {
                passwd = (string)InfoUtils.parTable["passwd"];
            }
            else
            {
                passwd = "000000";
            }
            string str = "SQTZ," + passwd + "," + this.timezoneCombox.SelectedValue + ","+this.gmtTextView.Text+",";
            if (InfoUtils.sendInfoTable.ContainsKey("SQTZ"))
            {
                InfoUtils.sendInfoTable.Remove("SQTZ");
            }
                InfoUtils.sendInfoTable.Add("SQTZ", str);
            this.timezoneGridView.Rows[0].Cells[0].Value=this.timezoneCombox.SelectedText ;
            this.timezoneGridView.Rows[0].Cells[1].Value=this.gmtTextView.Text;
            //SerialPortSender.sendStrInfo(str, this.serialPort);
        }

        private void timezoneRefresh_Click(object sender, EventArgs e)
        {
            if (InfoUtils.parTable["timezone"].Equals("+"))
            {
                this.timezoneGridView.Rows[0].Cells[0].Value = "东区";
            }
            else
            {
                this.timezoneGridView.Rows[0].Cells[0].Value = "西区";
            }
            this.timezoneGridView.Rows[0].Cells[1].Value = InfoUtils.parTable["gmt"];
            this.timezoneGridView.ClearSelection();
        }
    }
}

